package cn.ffcs.uec.organization.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import cn.ffcs.uec.common.vo.UecBdDefdoc;
import cn.ffcs.uec.organization.dao.UecOrgDeptDao;
import cn.ffcs.uec.staffAndOutStaff.vo.StaffAndOutStaff;
import cn.ffcs.uom.common.constants.BaseUnitConstants;
import cn.ffcs.uom.common.model.DefaultDaoFactory;
import cn.ffcs.uom.common.model.UomEntity;
import cn.ffcs.uom.common.util.ApplicationContextUtil;
import cn.ffcs.uom.common.util.StrUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * @Title:部门实体
 * @Description:
 * @Copyright: FFCS（C） 2017
 * @Company: FFCS
 * @author Wang Yiren
 * @Version 0.0.1 date:2017年12月11日
 * @since JDK1.6
 */
public class UecOrgDept extends UomEntity implements Serializable {

    private static final long serialVersionUID = -911321142364306868L;

    /**
     * 部门标识
     */
    public Long getDeptId() {
        return super.getId();
    }

    public void setDeptId(Long deptId) {
        super.setId(deptId);
    }

    /**
     * 集团模型部门主键
     */
    @Getter
    @Setter
    private String pkDept;

    /**
     * 帐期
     */
    @Getter
    @Setter
    private Long monthId;

    /**
     * 简称
     */
    @Getter
    @Setter
    private String shortname;

    /**
     * 编码
     */
    @Getter
    @Setter
    private String code;

    /**
     * 部门成立时间
     */
    @Getter
    @Setter
    private String createdate;

    /**
     * 负责人
     */
    @Getter
    @Setter
    private String principal;

    /**
     * 负责人（省内）--leader
     */
    @Getter
    @Setter
    private String leader;

    /**
     * 上级部门
     */
    @Getter
    @Setter
    private String pkFatherorg;

    /**
     * 部门类型
     */
    @Getter
    @Setter
    private Long depttype;

    /**
     * 显示顺序
     */
    @Getter
    @Setter
    private Double displayorder;

    /**
     * 名称
     */
    @Getter
    @Setter
    private String name;

    /**
     * HR撤销标志
     */
    @Getter
    @Setter
    private String hrcanceled;

    /**
     * 部门撤销日期
     */
    @Getter
    @Setter
    private String deptcanceldate;

    /**
     * 部门职责
     */
    @Getter
    @Setter
    private String deptduty;

    /**
     * 部门级别
     */
    @Getter
    @Setter
    private String deptlevel;

    /**
     * 创建时间
     */
    @Getter
    @Setter
    private String creationtime;

    /**
     * 创建人
     */
    @Getter
    @Setter
    private String creator;

    /**
     * 删除标示
     */
    @Getter
    @Setter
    private Long dr;

    /**
     * 启用状态
     */
    @Getter
    @Setter
    private Long enablestate;

    /**
     * 内部编码
     */
    @Getter
    @Setter
    private String innercode;

    /**
     * 是否最新版本
     */
    @Getter
    @Setter
    private String islastversion;

    /**
     * 最后修改时间
     */
    @Getter
    @Setter
    private String modifiedtime;

    /**
     * 最后修改人
     */
    @Getter
    @Setter
    private String modifier;

    /**
     * 所属业务单元
     */
    @Getter
    @Setter
    private String pkOrg;

    /**
     * 时间戳
     */
    @Getter
    @Setter
    private String ts;

    /**
     * 版本失效时间
     */
    @Getter
    @Setter
    private String venddate;

    /**
     * 版本号
     */
    @Getter
    @Setter
    private String vno;

    /**
     * 版本生效时间
     */
    @Getter
    @Setter
    private String vstartdate;

    /**
     * 分管领导
     */
    @Getter
    @Setter
    private String glbdef1;

    /**
     * 部门类型
     */
    @Getter
    @Setter
    private String glbdef2;

    /**
     * 机构类型
     */
    @Getter
    @Setter
    private String glbdef3;

    /**
     * 常用统计标识
     */
    @Getter
    @Setter
    private String glbdef6;

    /**
     * 渠道类型
     */
    @Getter
    @Setter
    private String glbdef7;

    /**
     * 部门层级关系
     */
    @Getter
    @Setter
    private String deptleve;

    /**
     * 是否承包单元
     */
    @Getter
    @Setter
    private String glbdef10;

    /**
     * 服务区域
     */
    @Getter
    @Setter
    private String glbdef11;

    /**
     * 单位属性
     */
    @Getter
    @Setter
    private String glbdef14;

    /**
     * 承包类型
     */
    @Getter
    @Setter
    private String glbdef15;

    /**
     * 划小单元承包类型
     */
    @Getter
    @Setter
    private String glbdef16;

    /**
     * 备注
     */
    @Getter
    @Setter
    private String memo;

    /**
     * 创建对象实例
     * 
     * @return
     */
    public static UecOrgDept newInstance() {
        return new UecOrgDept();
    }

    /**
     * 获取dao
     */
    public static UecOrgDeptDao repository() {
        return (UecOrgDeptDao) ApplicationContextUtil.getBean("uecOrgDeptDao");
    }

    /**
     * 主键
     * 
     * @return
     */
    public String getPkDeptName() {
        if (!StrUtil.isNullOrEmpty(this.getPkDept())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getPkDept());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 负责人
     * 
     * @return
     */
    public String getPrincipalName() {
        if (!StrUtil.isNullOrEmpty(this.getPrincipal())) {
            String sql = " SELECT * FROM  VIEW_SATFF_AND_OUTSATFF T WHERE T.PKPSNDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getPrincipal());
            List<StaffAndOutStaff> list = repository().jdbcFindList(sql, params, StaffAndOutStaff.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getStaffName();
            }
        }
        return "";
    }

    /**
     * 负责人（省内）--leader
     */
    public String getLeaderName() {
        if (!StrUtil.isNullOrEmpty(this.getLeader())) {
            if ("无".equals(this.getLeader())) {
                return "无";
            } else {
                String sql = " SELECT * FROM  VIEW_SATFF_AND_OUTSATFF T WHERE T.PKPSNDOC = ? ";
                List<Object> params = new ArrayList<Object>();
                params.add(this.getLeader());
                List<StaffAndOutStaff> list = repository().jdbcFindList(sql, params, StaffAndOutStaff.class);
                if (list != null && list.size() > 0) {
                    return list.get(0).getStaffName();
                }
            }
        }
        return "";
    }

    /**
     * 分管领导
     * 
     * @return
     */
    public String getGlbdef1Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef1())) {
            if ("无".equals(this.getGlbdef1())) {
                return "无";
            } else {
                String sql = " SELECT * FROM  VIEW_SATFF_AND_OUTSATFF T WHERE T.PKPSNDOC = ? ";
                List<Object> params = new ArrayList<Object>();
                params.add(this.getGlbdef1());
                List<StaffAndOutStaff> list = repository().jdbcFindList(sql, params, StaffAndOutStaff.class);
                if (list != null && list.size() > 0) {
                    return list.get(0).getStaffName();
                }
            }
        }
        return "";
    }

    /**
     * 上级部门
     * 
     * @return
     */
    public String getPkFatherorgName() {
        if (!StrUtil.isNullOrEmpty(this.getPkFatherorg())) {
            String sql = " SELECT * FROM  UEC_ORG_DEPT T WHERE T.STATUS_CD = ? AND T.PK_DEPT = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(BaseUnitConstants.ENTT_STATE_ACTIVE);
            params.add(this.getPkFatherorg());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 撤销标识
     * 
     * @return
     */
    public String getHrcanceledName() {
        if (!StrUtil.isNullOrEmpty(this.getHrcanceled())) {
            if ("N".equals(this.getHrcanceled())) {
                return "否";
            } else if ("Y".equals(this.getHrcanceled())) {
                return "是";
            }
        }
        return "";
    }

    /**
     * 部门级别
     * 
     * @return
     */
    public String getDeptlevelName() {
        if (!StrUtil.isNullOrEmpty(this.getDeptlevel())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getDeptlevel());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 所属业务单元
     * 
     * @return
     */
    public String getPkOrgName() {
        if (!StrUtil.isNullOrEmpty(this.getPkOrg())) {
            String sql = " SELECT * FROM uec_org_orgs WHERE pk_org = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getPkOrg());
            List<UecOrgOrgs> list = DefaultDaoFactory.getDefaultDao().jdbcFindList(sql, params, UecOrgOrgs.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return null;
    }

    /**
     * 部门类型
     * 
     * @return
     */
    public String getGlbdef2Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef2())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef2());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 机构类型
     * 
     * @return
     */
    public String getGlbdef3Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef3())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef3());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 常用统计标识
     * 
     * @return
     */
    public String getGlbdef6Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef6())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef6());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 渠道类型
     * 
     * @return
     */
    public String getGlbdef7Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef7())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef7());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 是否承包单元
     * 
     * @return
     */
    public String getGlbdef10Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef10())) {
            if ("N".equals(this.getGlbdef10())) {
                return "否";
            }
            if ("Y".equals(this.getGlbdef10())) {
                return "是";
            }
        }
        return "";
    }

    /**
     * 服务区域
     * 
     * @return
     */
    public String getGlbdef11Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef11())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef11());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 单位属性
     * 
     * @return
     */
    public String getGlbdef14Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef14())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef14());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 承包类型
     * 
     * @return
     */
    public String getGlbdef15Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef15())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef15());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }

    /**
     * 划小单元承包类型
     */
    public String getGlbdef16Name() {
        if (!StrUtil.isNullOrEmpty(this.getGlbdef16())) {
            String sql = " SELECT * FROM  UEC_BD_DEFDOC T WHERE T.PK_DEFDOC = ? ";
            List<Object> params = new ArrayList<Object>();
            params.add(this.getGlbdef16());
            List<UecBdDefdoc> list = repository().jdbcFindList(sql, params, UecBdDefdoc.class);
            if (list != null && list.size() > 0) {
                return list.get(0).getName();
            }
        }
        return "";
    }
}
